home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C21 / Binder1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  906 b   |  33 lines

  1. //: C21:Binder1.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Using STL "binders"
  7. #include "Generators.h"
  8. #include "copy_if.h"
  9. #include <algorithm>
  10. #include <vector>
  11. #include <iostream>
  12. #include <functional>
  13. using namespace std;
  14.  
  15. int main() {
  16.   const int sz = 10;
  17.   const int max = 40;
  18.   vector<int> a(sz), r;
  19.   URandGen urg(max);
  20.   ostream_iterator<int> out(cout, " ");
  21.   generate_n(a.begin(), sz, urg);
  22.   copy(a.begin(), a.end(), out);
  23.   int* d = find_if(a.begin(), a.end(), 
  24.     bind2nd(less<int>(), 20));
  25.   cout << "\n *d = " << *d << endl;
  26.   // copy_if() is not in the Standard C++ library
  27.   // but is defined later in the chapter:
  28.   copy_if(a.begin(), a.end(), back_inserter(r),
  29.     bind2nd(less<int>(), 20));
  30.   copy(r.begin(), r.end(), out);
  31.   cout << endl;
  32. } ///:~
  33.